package com.example.base.mvvm

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

abstract class BaseActivity<VDB:ViewDataBinding,VM:BaseViewModel> :AppCompatActivity(){
    //lateinit var 延迟初始化
    lateinit var binding:VDB
    lateinit var viewModel:VM

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //实例化binding 和 viewModel
        binding = DataBindingUtil.setContentView(this,getLayout())
        viewModel = ViewModelProvider(this)[getViewModel()]
        initView()
        initData()
    }
    abstract fun initView()
    abstract fun initData()

    abstract fun getViewModel(): Class<VM>

    abstract fun getLayout(): Int
}